// request
import {
  getManuLocations,
  getSources,
  getDirectiveTypes,
  getVisibles,
  getDirectiveStates
} from '@/api/common/IssueDirective/index.js'

/**
 * @desc 正面宣传指令
 */
export default {
  state: {
    directiveSource: [], // 指令来源
    manuPosition: [], // 上稿位置
    directiveType: [], // 指令类型
    viewScope: [], // 可视范围
    directiveState: []
  },

  actions: {
    /* 列出上稿位置可选项 */
    async getManuLocations({ commit }) {
      const res = await getManuLocations()
      const data = res.data.data || []
      commit('SET_LIST', { field: 'manuPosition', data })
    },

    /* 列出指令来源可选项 */
    async getSources({ commit }) {
      const res = await getSources()
      const data = res.data.data || []
      commit('SET_LIST', { field: 'directiveSource', data })
    },

    /* 列出指令类型可选项 */
    async getDirectiveTypes({ commit }) {
      const res = await getDirectiveTypes()
      const data = res.data.data || []
      commit('SET_LIST', { field: 'directiveType', data })
    },

    /* 列出可视范围可选项 */
    async getVisibles({ commit }) {
      const res = await getVisibles()
      const data = res.data.data || []
      commit('SET_LIST', { field: 'viewScope', data })
    },

    /* 查询指令状态列表 */
    async getDirectiveStates({ commit }) {
      const res = await getDirectiveStates()
      const data = res.data.data || []
      commit('SET_LIST', { field: 'directiveState', data })
    }
  },

  mutations: {
    SET_LIST(state, params) {
      state[params.field] = Object.freeze(params.data)
    },
  },

  getters: {
    directiveSource: (state) => state.directiveSource,
    manuPosition: (state) => state.manuPosition,
    directiveType: (state) => state.directiveType,
    viewScope: (state) => state.viewScope,
    directiveState: (state) => state.directiveState,
  }
}
